import request from '@/utils/request'
import type { MenuResponse } from '@/types/menu'

// 登录参数接口
export interface LoginDTO {
  username?: string
  password?: string
  number?: string
  type: '1' | '2'  // 1: 手机号登录, 2: 账号密码登录
  code: string
  result?: string
}

// 验证码响应接口
export interface CaptchaResponse {
  code: number
  msg: string | null
  data: string
}

// 登录响应接口
export interface LoginResponse {
  code: number
  msg: string | null
  data: string  // token
}

// 获取验证码
export function getCaptcha() {
  return request<any, CaptchaResponse>({
    url: '/auth/login/code',
    method: 'get'
  })
}

// 登录
export function login(data: LoginDTO) {
  return request<any, LoginResponse>({
    url: '/auth/login',
    method: 'post',
    data
  })
}

// 退出登录
export function logout() {
  return request<any, LoginResponse>({
    url: '/auth/logout',
    method: 'get'
  })
}

export function initMenu() {
  return request<any, MenuResponse>({
    url: '/system/res/tree',
    method: 'get'
  })
}
